package org.client.otdr.executor;

import org.client.otdr.Executor;
import org.client.otdr.OTDRID;
import org.client.otdr.OtdrDomainService;
import org.client.otdr.resolver.MarkerResolver;
import org.openems.entity.Key;
import org.openems.entity.MarkerEntity;
import org.openems.entity.Unit;

import framework.AbstractDomainService.ActiveAccessor;
import framework.AccessorHelper;
import framework.AccessorHelperImpl;
import framework.webclient.RestSocket;
import framework.webclient.SystemProperty;

public class AutoSearchExecutor implements Executor {

	private AccessorHelper accessor;
	private ResolverAccessor resolverAccessor;

	public AutoSearchExecutor(ActiveAccessor accessor, RestSocket restSocket,
			ResolverAccessor resolverAccessor) {
		this.accessor = new AccessorHelperImpl(accessor);
		this.resolverAccessor = resolverAccessor;
	}

	@Override
	public void execute(Key key) {
		if (accessor.getSelectedItem(OTDRID.get().AUTOSEARCH).equals(OtdrDomainService.AUTOSEARCH_START)) {
			MarkerEntity entity = new MarkerEntity(null, "Marker", getClass().getResource("/org/client/otdr/Number-1-icon.png").toExternalForm(), 
					3, Unit.none(), Double.MIN_VALUE, Double.MAX_VALUE, true);
			
			accessor.addChild(OTDRID.get().MARKERLIST, entity);
			accessor.setSelectedItem(OTDRID.get().AUTOSEARCH, OtdrDomainService.AUTOSEARCH_STOP);
			
			resolverAccessor.add(entity.getKey(), new MarkerResolver(entity.getKey()));
		}		
	}

}
